package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.DeleteMapping;

import java.util.List;

/**
 * @author jiang
 */
@Mapper
public interface ShoppingCartMapper {

    /**
     * 查询购物车中是否存在该商品
     * @param shoppingCart
     * @return
     */
    ShoppingCart getRecord(ShoppingCart shoppingCart);

    /**
     * 更新购物车数据
     * @param shoppingCart
     */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateRecord(ShoppingCart shoppingCart);

    /**
     * 添加购物车数据
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart values (null,#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void addRecord(ShoppingCart shoppingCart);

    /**
     * 查看购物车
     * @param userId
     * @return
     */
    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> list(Long userId);

    /**
     * 清空购物车
     * @param userId
     */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void deleteShoppingCart(Long userId);

    /**
     * 删除购物车中的一个商品
     * @param shoppingCart
     */
    @Delete("delete from shopping_cart where id = #{id}")
    void sub(ShoppingCart shoppingCart);
}
